package com.springboot.cloud.demos.ribbon.rest;

import com.springboot.cloud.common.core.entity.vo.Result;
import com.springboot.cloud.demos.entity.form.CouponForm;
import com.springboot.cloud.demos.entity.param.CouponQueryParam;
import com.springboot.cloud.demos.ribbon.service.CouponService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
public class CouponController {

    @Autowired
    private CouponService couponService;

    @PostMapping("/coupon/conditions")
    public Result conditions(@RequestBody CouponQueryParam params) {
        return couponService.conditions(params);
    }

    @PostMapping("/coupon")
    public Result add(@RequestBody CouponForm couponForm) {
        return couponService.save(couponForm);
    }

    @PutMapping(value = "/coupon")
    public Result update(@RequestBody CouponForm coupon) {
        return couponService.update(coupon);
    }

    @GetMapping("/coupon/{id}")
    public Result get(@PathVariable(value = "id") String id) {
        return couponService.coupon(id);
    }

    @DeleteMapping("/coupon/{id}")
    public void delete(@PathVariable(value = "id") String id) {
        couponService.delete(id);
    }
}
